<?php

 require_once('sql_connection.php');
 
 class Sql_area extends Sql_connection {
 	function __construct() {
 		parent :: __construct();
 	}
 	
 	/**
 	 * Function returns an array of areas, or null if no results.
 	 */
 	function get_areas() {
		$query = "SELECT area FROM Area ORDER BY area ASC";
		
		$result = mysql_query($query);
		if (!$result)
			die ("Could not send query, DB error: " . mysql_error());
		
		return column_as_array($result);
			
		
	}
	
	
	/**
	 * Function that returns areas, with longitude and latitude
	 */ 
	 function get_areas_with_pos() {
	 	
	 	$query = "SELECT area, lat, lon FROM Area ORDER BY area ASC";

		$result = mysql_query($query);
		
		if (!$result)
			die ("Could not send query, DB error: " . mysql_error());
			
		$areas = Array();
		while ($row = mysql_fetch_assoc($result))
			$areas[] = $row;
		
		return $areas;
	 }
	 
	 /**
	  * Function to check if area exists
	  */
	  
	function exists($area) {
		$area = mysql_input($area);
		$query = "SELECT area FROM Area WHERE area = '$area'";
		
		$result = mysql_query($query);
		if (!$result)
			die ("sql_area-> exists() DB error: " . mysql_error());
		
		if (mysql_num_rows($result) > 0)
				return true;
			else
				return false;	 	
	}
 }
?>
